using System;
using System.Runtime.Serialization;

namespace Metro.Admin.BusinessEntities
{
    [DataContract]
	public class User {

       
        private string customerId=string.Empty;
        private string customerName = string.Empty;
        private DateTime datePasswordExpiration;
        private string id = string.Empty;
        private string lastName = string.Empty;
        private DateTime lastNotificationSrv;
        private string name = string.Empty;
        private State state;
        private string email = string.Empty;
        private string hash = string.Empty;
        private string salt = string.Empty;
        private DateTime lastLoginDate;
        private int failedPasswordAttemptCount = 0;
        private string passwordQuestion = string.Empty;
        private string passwordAnswer = string.Empty;
        private UserType userType;
        private string login= string.Empty;
        private string password=string.Empty;
        private decimal position = 0;
        private decimal profit = 0;
        private decimal avgBuy = 0;
        private decimal avgSell = 0;
        private decimal customerCommision = 0;
        private string technicalNameCustomer = string.Empty;
        private decimal transitBuyCredit = 0;
        private decimal transitSellCredit = 0;
        private decimal sellCredit = 0;
        private decimal buyCredit = 0;
        private CustomerType customerType;

		public User(){

		}

        public User(string id, string login, string idCustomer, UserType userType, DateTime passwordExpiration, string surename, string name, State state, string salt, string hash, DateTime lastLoginDate, int failedPasswordAttemptCount, string email, string passwordQuestion, string passwordAnswer)
        {
            this.id = id;
            this.login = login; 
            this.customerId = idCustomer;
            this.userType = userType;
            this.datePasswordExpiration = passwordExpiration;
            this.lastName = surename;
            this.name = name;
            this.state = state;
            this.salt = salt;
            this.hash = hash;
            this.lastLoginDate = lastLoginDate;
            this.failedPasswordAttemptCount = failedPasswordAttemptCount;
            this.email = email;
            this.passwordQuestion = passwordQuestion;
            this.passwordAnswer = passwordAnswer;  
        }

        [DataMember]
        public String Login
        {
            get { return this.login; }
            set { this.login = value; }
        }

        [DataMember]
        public String Password
        { 
            get { return this.password; }
            set { this.password = value; }
        }

        [DataMember]
        public DateTime DatePasswordExpiration
        {
            get { return this.datePasswordExpiration; }
            set { this.datePasswordExpiration = value; }
        }

        [DataMember]
        public DateTime LastNotificationSrv
        {
            get { return this.lastNotificationSrv; }
            set { this.lastNotificationSrv = value; }
        }

        [DataMember]
        public String CustomerId
        {
            get { return this.customerId; }
            set { this.customerId = value; }
        }

        [DataMember]
        public String CustomerName
        {
            get { return this.customerName; }
            set { this.customerName = value; }
        }

        [DataMember]
        public String Id
        {
            get { return this.id; }
            set { this.id = value; }
        }

        [DataMember]
        public String Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        [DataMember]
        public String LastName
        {
            get { return this.lastName; }
            set { this.lastName = value; }
        }

        [DataMember]
        public UserType UserTypeProp
        {
            get { return this.userType; }
            set { this.userType = value; }
        }

        [DataMember]
        public string UserTypeString
        {
            get { return Enum.GetName(typeof(UserType),this.userType); }
            set { this.userType = UserServices.String2UserType(value); }
        }

        [DataMember]
        public string[] Roles
        {
            get { return UserServices.GetRoles(this.userType); }
            set { }
        }

        [DataMember]
        public State State
        {
            get { return this.state; }
            set { this.state = value; }
        }

        [DataMember]
        public String Email
        {
            get { return this.email; }
            set { this.email = value; }
        }

        [DataMember]
        public String Hash
        {
            get { return this.hash; }
            set { this.hash = value; }
        }

        [DataMember]
        public String Salt
        {
            get { return this.salt; }
            set { this.salt = value; }        
        }

        [DataMember]
        public DateTime LastLoginDate
        {
            get { return this.lastLoginDate; }
            set { this.lastLoginDate = value; } 
        }

        [DataMember]
        public int FailedPasswordAttemptCount
        {
            get { return this.failedPasswordAttemptCount; }
            set { this.failedPasswordAttemptCount = value; } 
        }

        [DataMember]
        public String PasswordQuestion
        {
            get { return this.passwordQuestion; }
            set { this.passwordQuestion = value; } 
        }

        [DataMember]
        public String PasswordAnswer
        {
            get { return this.passwordAnswer; }
            set { this.passwordAnswer = value; } 
        }

        [DataMember]
        public Decimal Position
        {
            get { return this.position; }
            set { this.position = value; }
        }

        [DataMember]
        public Decimal Profit
        {
            get { return this.profit; }
            set { this.profit = value; }
        }

        [DataMember]
        public Decimal AvgBuy
        {
            get { return this.avgBuy; }
            set { this.avgBuy = value; }
        }

        [DataMember]
        public Decimal AvgSell
        {
            get { return this.avgSell; }
            set { this.avgSell = value; }
        }

        [DataMember]
		public Decimal CustomerCommision
        {
            get { return this.customerCommision; }
            set { this.customerCommision = value; }
        }

        [DataMember]
        public String TechnicalNameCustomer
        {
            get { return this.technicalNameCustomer; }
            set { this.technicalNameCustomer = value; }
        }
        
        [DataMember]
        public Decimal BuyCredit
        {
            get { return this.buyCredit; }
            set { this.buyCredit = value; }
        }

        [DataMember]
        public Decimal SellCredit
        {
            get { return this.sellCredit; }
            set { this.sellCredit = value; }
        }

        [DataMember]
        public Decimal TransitBuyCredit
        {
            get { return this.transitBuyCredit; }
            set { this.transitBuyCredit = value; }
        }

        [DataMember]
        public Decimal TransitSellCredit
        {
            get { return this.transitSellCredit; }
            set { this.transitSellCredit = value; }
        }

        [DataMember]
        public CustomerType CustomerType
        {
            get { return this.customerType; }
            set { this.customerType = value; }
        }
	}

    [DataContract(Name = "UserType")]
    public enum UserType
    {
        [EnumMember] 
        Adm,
        [EnumMember] 
        RiskAdm,
        [EnumMember] 
        CustomerAdm,
        [EnumMember] 
        UserAdm,
        [EnumMember] 
        Trader,
        [EnumMember] 
        User,
        [EnumMember] 
        DeskPpal,
        [EnumMember] 
        SalesForce
    }

    [DataContract]
    public static class UserServices
    {
        public static string UserTypeName(UserType userType)
        {
            string retName = string.Empty;

            switch (userType)
            {
                case UserType.Adm:
                    retName = "Adm";
                    break;
                case UserType.CustomerAdm:
                    retName = "CustomerAdm";
                    break;
                case UserType.RiskAdm:
                    retName = "RiskAdm";
                    break;
                case UserType.UserAdm:
                    retName = "UserAdm";
                    break;
                case UserType.Trader:
                    retName = "Trader";
                    break;
                case UserType.User:
                    retName = "User";
                    break;
                case UserType.DeskPpal:
                    retName = "DeskPpal";
                    break;
                case UserType.SalesForce:
                    retName = "SalesForce";
                    break;
            }

            return retName;
        }

        public static UserType String2UserType(string userType)
        {
            UserType retUserType=UserType.Adm;

            switch (userType)
            {
                case "Adm":
                    retUserType = UserType.Adm;
                    break;
                case "CustomerAdm":
                    retUserType = UserType.CustomerAdm;
                    break;
                case "RiskAdm":
                    retUserType = UserType.RiskAdm;
                    break;
                case "UserAdm":
                    retUserType = UserType.UserAdm;
                    break;
                case "Trader":
                    retUserType = UserType.Trader;
                    break;
                case "User":
                    retUserType = UserType.User;
                    break;
                case "DeskPpal":
                    retUserType = UserType.DeskPpal;
                    break;
                case "SalesForce":
                    retUserType = UserType.SalesForce;
                    break;
            }

            return retUserType;
        }

        public static string[] GetRoles(UserType userType)
        {
            string[] roles;

            string userTypeString = UserTypeName(userType);

            roles = new string [1];
            roles.SetValue(userTypeString, 0);
            return roles;
        }
    }
}
